﻿using RemoteSensingImageDirectServer.Untils.Pool;
using System.ComponentModel.DataAnnotations;

namespace RemoteSensingImageDirectServer.Models.Request.Validation
{

    public class EPSGValueAttribute : ValidationAttribute
    {
        private readonly string[] _attrs;

        private readonly string _constKey;
        public EPSGValueAttribute(string key)
        {
            this._constKey = key;
            this._attrs = OsrTransformPool.Instance().EPSGKeys;
        }

        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value is string str && !string.IsNullOrWhiteSpace(str))
            {
                if (_attrs.Contains(str.ToLower()))
                    return ValidationResult.Success;
                else
                    return new ValidationResult($"{this._constKey} value required value should be between [{string.Join(",", this._attrs)}].");
            }
            return new ValidationResult($"{this._constKey} value required value should be between [{string.Join(",", this._attrs)}].");
        }
    }
}
